﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace GameSPK
{
    public enum loaidukien
    {
        info,
        media
    }
    public class MultiEvent
    {
        public ChuDe chuDe { set; get; }
        public string cauhoi { set; get; }
        public string dapan { set; get; }
        public int sodukien { set; get; }
        public List<CEvent> lstDuKien { set; get; }
        public CEvent this[int index]
        {
            get
            {
                return this.lstDuKien[index];
            }
            set
            {
                this.lstDuKien.Add(value);
            }
        }
        public MultiEvent()
        {
            lstDuKien = new List<CEvent>();
        }
        String filename;
        public bool SaveDB()
        {
            bool result = true;
            return result;
        }
        public void SaveXML(String filename)
        {
            this.filename = filename; 
            var layout = new XElement("MultiEventContent",
                new XElement("MainEvent",
                    new XAttribute("ChuDe", chuDe.MaCD),
                    new XAttribute("CauHoi", cauhoi),
                    new XAttribute("DapAn",dapan),
                    new XAttribute("SoEvent", sodukien)
                 )
                 );

            var childEvent = new XElement("Events"

                );
            for (int i = 0; i < sodukien; i++)
            {
                XElement cau = new XElement("Event" + i,
                    new XAttribute("LoaiEvent", this[i].eloaiDuKien.ToString()),
                    new XAttribute("NoiDung", this[i].NoiDung)
                    
                    );
                childEvent.Add(cau);
            }

            layout.Add(childEvent);
            layout.Save(filename);
        }
    }
    public class CEvent
    {
        public loaidukien eloaiDuKien { set; get; }
        public string NoiDung { set; get; }
    }
}
